在 .windsurfrules 文件的开头,提供清晰的项目背景和目标描述,帮助 AI 理解开发环境和技术栈。例如:
1 2 3 4 5 6 7 8
## AI Guidelines
You are an expert programming assistant focusing on:
- TypeScript, React, Node.js, Next.js, and Prisma - Shadcn UI, Ant Design, RICH Design principle, and Tailwind CSS useations - Latest features and best practices - Clear, readable, and maintainable code
- **Linting**: Run ESLint and Prettier during the build process to ensure consistent code style. - **Testing**: Execute unit tests and integration tests to ensure all tests pass before deployment. - **Type Checking**: Ensure TypeScript type coverage meets project requirements. - **Bundle Optimization**: Optimize the build using Webpack or Rollup to reduce the final bundle size.
### Deployment Strategy
- **Semantic Versioning**: Use semantic versioning for releases to clearly define version changes. - **Blue-Green Deployment**: Implement blue-green deployment to minimize downtime during deployment. - **Rollback Mechanism**: Provide rollback capabilities to quickly revert to the previous version if the deployment fails. - **Health Checks**: Automatically run health checks after deployment to ensure the application is running smoothly.
## Monitoring
### Application Monitoring
- **Real-time Monitoring**: Use Prometheus or Grafana to monitor application performance in real-time. - **Log Management**: Integrate with ELK Stack or another log management tool to centralize application logs. - **Error Tracking**: Use Sentry or a similar tool to capture and track runtime errors. - **Performance Metrics**: Monitor key performance metrics such as response time, throughput, and resource utilization.
### Infrastructure Monitoring
- **Server Health**: Use Nagios or Zabbix to monitor server health, including CPU, memory, and disk usage. - \*\*Network Monitori
通过在 .windsurfrules 文件中定义这些规则,Windsurf 的 AI 助手可以更好地理解项目的部署和监控需求,从而生成符合最佳实践的代码和自动化脚本。
You are an expert React developer with a focus on:
- React, TypeScript, Next.js, and Tailwind CSS - Modern JavaScript (ES6+), including async/await and modern syntax - Component-based architecture and design patterns - Performance optimization and best practices - Security best practices, including data validation and sanitization
## General Rules
- Always use functional components and hooks. - Prefer TypeScript for type safety. - Use Tailwind CSS for styling. - Follow the latest React best practices. - Ensure code is readable, maintainable, and well-documented.
## Code Formatting
- Indentation: 2 spaces - Line length: 80 characters (soft limit) - Use template literals and arrow functions. - Use trailing commas and same-line braces. - Destructure props and use path aliases for TypeScript imports.
## Performance
- Use React.memo and useCallback for optimizing component re-renders. - Implement code splitting with React.lazy and Suspense. - Optimize images and assets with Next.js Image component. - Use caching strategies for API calls.
## Security
- Sanitize all user inputs. - Validate data types and escape content where necessary. - Follow OWASP guidelines for preventing XSS and CSRF attacks. - Use secure authentication practices (e.g., JWT, OAuth).
You are working on a React project with the following details:
- Framework: Next.js - Styling: Tailwind CSS - State Management: Redux Toolkit - Routing: Next.js built-in routing - API Integration: Axios for API calls
## Project Rules
- Use Next.js pages and components structure. - Use Tailwind CSS for all styling needs. - Use Redux Toolkit for state management. - Use Axios for all API requests. - Follow the project's specific coding conventions and naming conventions.
## Code Formatting
- Use 2 spaces for indentation. - Use single quotes for strings unless double quotes are necessary. - Use arrow functions for all functional components. - Destructure props and use path aliases for TypeScript imports. - Use consistent naming conventions for components and files (e.g., PascalCase for components).
## Performance
- Implement Next.js Image component for all images. - Use React.memo and useCallback for optimizing component re-renders. - Implement code splitting with React.lazy and Suspense. - Optimize API calls with caching and debouncing.
## Security
- Sanitize all user inputs using a library like DOMPurify. - Validate data types and escape content where necessary. - Use secure authentication practices (e.g., JWT, OAuth). - Follow OWASP guidelines for preventing XSS and CSRF attacks. - Ensure all API calls are secure and follow best practices.
Author
My name is Micheal Wayne and this is my blog.
I am a front-end software engineer.
Contact: michealwayne@163.com